Skip to content

Fix answers disappearing in the hierarchy view when scrolling#7280

Open
grzesiek2010 wants to merge 1 commit into
getodk:masterfrom
grzesiek2010:COLLECT-7275
Open

Fix answers disappearing in the hierarchy view when scrolling#7280
grzesiek2010 wants to merge 1 commit into
getodk:masterfrom
grzesiek2010:COLLECT-7275

Conversation

@grzesiek2010

@grzesiek2010 grzesiek2010 commented Jun 24, 2026

Copy link
Copy Markdown
Member

Closes #7275

Why is this the best possible solution? Were any other approaches considered?

The problem was not specific to question types and was not limited to image questions, as suggested in the issue. It was a general issue affecting question answers rendered with Jetpack Compose while being hosted inside a RecyclerView, as we are currently in the process of gradually migrating our UI to Jetpack Compose.

I initially expected this setup to work out of the box, but it appears there are some issues with combining Compose-based views and RecyclerView in this way.

As explained in the comment, the issue was caused by the answer components not being measured correctly: a ComposeView reused from the RecyclerView pool keeps a stale, collapsed (0-height) measurement and is never re-measured on rebind, so the row renders blank. Fresh views work because they go through a full measure/layout pass.

I considered other approaches such as

  1. Changing ViewCompositionStrategy
  2. Calling disposeComposition() on recycle
  3. Disabling recycling for these rows
  4. Migrating RecyclerView to LazyColumn

1,2 The first two don't help (the problem is layout-related, not a composition lifecycle issue).
3 Disabling recycling would give up on view recycling entirely.
4 Migrating to LazyColumn should help but that would require way more changes and would be riskier.

Forcing a remeasure after composition keeps recycling intact and is the least invasive fix.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Question answers in the form hierarchy view no longer disappear after scrolling through a long list. The change is limited to how answer rows in the hierarchy view are laid out, so the regression risk is confined to that screen - mainly the rendering and sizing of answer rows as they are scrolled and recycled.

Do we need any specific form for testing your changes? If so, please attach one.

Any form with many questions, so that the list in the hierarchy is long.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

No.

Before submitting this PR, please make sure you have:

  • added or modified tests for any new or changed behavior
  • run ./gradlew connectedAndroidTest (or ./gradlew testLab) and confirmed all checks still pass
  • added a comment above any new strings describing it for translators
  • added any new strings with date formatting to DateFormatsTest
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@grzesiek2010 grzesiek2010 marked this pull request as ready for review June 25, 2026 06:10
@grzesiek2010 grzesiek2010 requested a review from seadowg June 25, 2026 06:10
// A ComposeView reused from the RecyclerView pool gets measured to 0 height on
// rebind, so the row renders blank after scrolling. Nudge a remeasure after
// composition to apply the real height.
SideEffect {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on Slack, it'd be good to see if we can call requestLayout after setContextThemedContent on ComposeView or just use MutableState hosted in HierarchyListItemView to mutate the content (with only a single call to setContextThemedContent). These options would allow us to avoid SideEffect which can be hard to reason about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some image questions disappear from hierarchy view after filling other questions

2 participants